﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Xml;

using iTextSharp.text.pdf;

namespace iPdf
{
    public enum WorkStatus
    {
        Idle = 0,
        Busy = 1,
        TaskImported = 2
    }

    public enum JumpDirection
    {
        Previous = 0,
        Next = 1,
        First = 2,
        Last = 3
    }

    public enum PrintingPermissionID
    {
        None = 0,
        LowResolution = 1,
        HighResolution = 2
    }

    public enum EditingPermissionID
    {
        None = 0,
        ManipulatePages = 1,
        FillingInFormFieldsAndSigning = 2,
        FillingInFormFieldsAndSigningAndCommenting = 3,
        AllExceptPageExtraction = 4
    }

    public enum SecurityLevelID
    {
        None = 0,
        PasswordSecurity = 1,
        CertificateSecurity = 2
    }

    public struct PdfLetOption
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public bool? Bookmark;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public bool? Hyperlink;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public bool? Navigator;
    }

    class SecurityLevel
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public SecurityLevelID ID;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public string Text;
        
        public SecurityLevel(SecurityLevelID id, string text)
        {
            ID = id;
            Text = text;
        }

        public override string ToString()
        {
            return Text;
        }
    }

    class Permission
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public bool AllowCopyContent;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public bool AllowScreenReader;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public PrintingPermissionID PrintingPermission;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public EditingPermissionID EditingPermission;

        public int Permissions
        {
            get
            {
                int permissions = 0;
                if (AllowCopyContent)
                {
                    permissions |= PdfWriter.ALLOW_COPY;
                }

                if (AllowScreenReader)
                {
                    permissions |= PdfWriter.ALLOW_SCREENREADERS;
                }

                switch (PrintingPermission)
                {
                    case PrintingPermissionID.HighResolution:
                        permissions |= PdfWriter.ALLOW_PRINTING;
                        break;

                    case PrintingPermissionID.LowResolution:
                        permissions |= PdfWriter.ALLOW_DEGRADED_PRINTING;
                        break;
                }

                switch (EditingPermission)
                {
                    case EditingPermissionID.ManipulatePages:
                        permissions |= PdfWriter.AllowAssembly;
                        break;

                    case EditingPermissionID.FillingInFormFieldsAndSigning:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn;
                        break;

                    case EditingPermissionID.FillingInFormFieldsAndSigningAndCommenting:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn |
                                                    PdfWriter.AllowModifyAnnotations;
                        break;

                    case EditingPermissionID.AllExceptPageExtraction:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn |
                                                    PdfWriter.AllowModifyAnnotations |
                                                    PdfWriter.AllowModifyContents;
                        break;
                }

                return permissions;
            }
        }
    }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
    public struct BalloonTip
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public string Title;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public string Text;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public int Timeout;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public ToolTipIcon Icon;
    }

    public enum CertifyLevelID
    {
        NotCertified = PdfSignatureAppearance.NOT_CERTIFIED,
        NoChangesAllowed = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,
        FormFilling = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,
        FormFillingAndAnnotations = PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
    }

    class CertifyLevel
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
        public CertifyLevelID ID;
        string Description;

        static int CurrentID;

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.ToString")]
        public CertifyLevel(string description)
        {
            ID = (CertifyLevelID) CurrentID;
            ++CurrentID;
            Description = CurrentID.ToString() + ". " + description;
        }

        public override string ToString()
        {
            return Description;
        }
    }

    public enum CertificateSource
    {
        System,
        File
    }


    class BookmarkNode
    {
        private Hashtable map ;

        public Hashtable Map
        {
            get
            {
                return map;
            }
        }

        public bool IsTopLevelNode
        {
            get
            {
                return Parent == null;
            }
        }

        public int Level
        {
            get
            {
                return map["Level"] == null? 0 : (int)map["Level"];
            }
        }

        public Hashtable Parent
        {
            get
            {
                return (Hashtable)map["Parent"];
            }
        }

        public BookmarkNode ParentNode
        {
            get
            {
                return new BookmarkNode(Parent);
            }
        }


        public void AddKid(BookmarkNode node)
        {
            AddKid(node.map);
        }

        public void AddKid(Hashtable kid)
        {
            if (map["Kids"] == null)
            {
                map["Kids"] = new ArrayList();
            }

            ArrayList kids = (ArrayList)map["Kids"];
            kids.Add(kid);
            kid["Parent"] = map;
        }

        public BookmarkNode()
        {
            map = new Hashtable();
        }

        public BookmarkNode(Hashtable node)
        {
            this.map = node;
        }
    }

    public enum FileStatus
    {
        Normal,
        InUse,
        NotExist
    }

    public enum OfficeDocumentType
    {
        WordDocument = 0,
        ExcelSheet,
        PowerPointPresentation
    }

}
